/*
 * Project: Daycare Web Application
 * Package: com.made2ordersoftware.daycare.domain
 * File:    PhoneEntity.java
 * Created: Dec 20, 2010
 */
/**
 * Copyright (c) 2010 Made 2 Order Software, LLC
 *
 * All rights reserved. No part of this software may be reproduced, stored in a retrieval system, or
 * transmitted in any form or by any means, without the prior written permission of Made 2 Order Software.
 *
 * You may not distribute the URL or redistribute the files to third parties. You may transfer the files onto
 * a single storage device so long as you can prove ownership of the software. You may not reverse engineer,
 * decompile, or disassemble the software or media files. You may not modify or translate the software or
 * media, or distribute copies of the software or media without the written consent of Made 2 Order Software,
 * LLC.
 */
package com.made2ordersoftware.daycare.domain;

import java.io.Serializable;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.made2ordersoftware.daycare.domain.enums.PhoneType;
import com.made2ordersoftware.util.StringUtility;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Entity class representing the a phone numbers of registered parents.
 *
 * @author David Canning <dcannin@gmail.com>
 * @version 1.0.0
 */
@Entity
@Table(name = "phone_number")
@XmlRootElement
public class PhoneEntity implements Serializable {

    private static final Logger LOG = LoggerFactory.getLogger(PhoneEntity.class);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    private Long id;
    @Basic(optional = false)
    private String number;
    @Basic(optional = false)
    @Enumerated(EnumType.STRING)
    private PhoneType type;
    @JoinColumn(name = "person_id", referencedColumnName = "id", nullable = false, updatable = false)
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private ParentEntity parent;

    /**
     * Creates an instance of <code>PhoneEntity</code>.
     */
    public PhoneEntity() {
    }

    /**
     * Creates an instance of <code>PhoneEntity</code>.
     *
     * @param phoneNumber
     * @param type
     */
    public PhoneEntity(String phoneNumber, PhoneType type) {
        this.number = phoneNumber;
        this.type = type;
    }

    /**
     *
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets the id
     *
     * @param id
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @return the phone number
     */
    public String getNumber() {
        return number;
    }

    /**
     * Sets the phone number.
     *
     * @param phoneNumber the phone number to set
     */
    public void setNumber(String phoneNumber) {
        this.number = phoneNumber;
    }

    /**
     * @return the type of phone
     */
    public PhoneType getType() {
        return type;
    }

    /**
     * Sets the type of phone.
     *
     * @param phoneType
     */
    public void setType(PhoneType phoneType) {
        this.type = phoneType;
    }

    /**
     *
     * @return the parent
     */
    public ParentEntity getParent() {
        return parent;
    }

    /**
     * Sets the parent
     *
     * @param parent
     */
    public void setParent(ParentEntity parent) {
        this.parent = parent;
    }

    @Override
    public int hashCode() {
        int hash = 6;
        hash = 23 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof PhoneEntity)) {
            return false;
        }
        final PhoneEntity other = (PhoneEntity) object;
        return Objects.equals(this.id, other.getId());
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder("\nPhoneEntity{ id=").append(
                StringUtility.ifNotNullToString(getId()));
        sb.append("\n\tParent ID=").append(this.parent.getId());
        sb.append("\n\tNumber=").append(this.number);
        sb.append("\n\tType=").append(this.type);
        sb.append("}");
        return sb.toString();
    }

}
